package com.loco.handsomemo.lib_keyboard;

import android.app.Activity;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;

public enum  KeyBoardWrapper {
    INSTANCE;

    private CWKeyboardUtil keyboardUtil;

    /**
     * 初始化edittext 所依赖的键盘
     * @param act 传入activity为了禁用 原生键盘
     * @param rootView 键盘需要绑定的view
     * @param ets
     */

    public void  initKeyBoard(Activity act, ViewGroup rootView, EditText ... ets){
        //禁用原生键盘弹出
        act.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        if (ets==null||ets.length<=0)return;
        keyboardUtil = new CWKeyboardUtil(act,  rootView, null);
        keyboardUtil.showKeyBoardLayout(ets[0],  CWKeyboardUtil.INPUTTYPE_ABC, -1);
        for (EditText et:ets) {
            et.getInputType();
            et.setOnTouchListener(new KeyboardTouchListener(keyboardUtil, CWKeyboardUtil.INPUTTYPE_ABC, -1));
        }
    }

    /**
     * 获取自定义键盘是否是站时状态 true 展示中 ，false 未展示
     * @return
     */
    public boolean getKeyboardState(){
        return keyboardUtil!=null&&keyboardUtil.getKeyboardState();
    }

    /**
     * 隐藏键盘 包括系统键盘
     */
    public void hideCWKeyboard(){
        if (keyboardUtil==null)return;
        keyboardUtil.hideAllKeyBoard();
    }
}
